//ST表-模版题(区间gcd)
#include <iostream>
using namespace std;
const int N = 1010;
int n, m;
int a[N];
int f[N][25];
int lg[N];

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

void init()
{
    lg[0] = -1;
    for(int i = 1; i <= n; i++)
    {
        f[i][0] = a[i];
        lg[i] = lg[i >> 1] + 1; 
    }

    for(int j = 1; (1 << j) <= n; j++)
        for(int i = 1; i + (1 << j) - 1 <= n; i++)
            f[i][j] = gcd(f[i][j-1], f[i + (1 << (j - 1))][j-1]);
}

int query(int l, int r)
{
    int k = lg[r - l + 1]; 
    return gcd(f[l][k], f[r - (1 << k) + 1][k]);
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    init();
    for(int i = 1; i <= m; i++)
    {
        int l, r; cin >> l >> r;
        cout << query(l, r) << endl;
    }
    return 0;
}